package com.api.shopapi.mapper;


import com.api.shopapi.entity.BusinessRel;
import com.api.shopapi.entity.dto.BusinessRelDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
@Mapper
public interface BusinessRelMapper {

    @Insert("insert into business_rel(BusinessRelCode,BusinessTopCode,BusinessCode) values " +
            "(#{businessRel.businessRelCode},#{businessRel.BusinessTopCode}," +
            "#{businessRel.BusinessCode})")
    int insert(@Param("businessRel") BusinessRel businessRel);


    @Delete("delete from business_rel where businessRelCode=#{businessRelCode}")
    int deleteByBusinessRelCode(@Param("businessRelCode") String businessRelCode);


    @Update("update business_rel set BusinessTopCode=#{businessRel.BusinessTopCode}," +
            "BusinessCode=#{businessRel.BusinessCode} "+
            " where BusinessRelCode=#{businessRel.BusinessRelCode}")
    int updateByBusinessRelCode(@Param("businessRel") BusinessRel businessRel);


    @Select("select * from business_rel where businessRelCode=#{businessRelCode} limit 1")
    BusinessRel getByBusinessRelCode(@Param("businessRelCode") String businessRelCode);

    @Select("select * from business_rel where businessCode=#{businessCode} limit 1")
    BusinessRel getByBusinessCode(@Param("businessCode") String businessCode);


    @Select("select * from business_rel")
    List<BusinessRel> getList();

    @Select("select * from business_rel where businessTopCode=#{businessTopCode}")
    List<BusinessRel> getListByBusinessTopCode(String businessTopCode);

    @Select("select * from business_rel")
    List<BusinessRelDTO> getListBusinessRelDTO();

}
